using System;
using System.Collections;

namespace Scenario.Modules.FormHelper
{
	/// <summary>
	/// Summary description for FormAttributeAction.
	/// </summary>
	public class FormAttributeAction
	{
		private FormAttributeOperations IN;
		private FormAttributeOperations OUT;

		public FormAttributeAction()
		{
			IN= new FormAttributeOperations();
			OUT= new FormAttributeOperations();
		}

		public FormAttributeOperations In 
		{
			get { return this.IN;}
			//set { this.docId = value; }
		}
		public FormAttributeOperations Out 
		{
			get { return this.OUT;}
			//set { this.docId = value; }
		}

		public void AddIN(FormAttributeOperation o)
		{
			this.IN.Add(o);
		}
		
		public void AddOUT(FormAttributeOperation o)
		{
			this.OUT.Add(o);
		}

		public int SearchDocIDForIN(string sDocID, string sRes)
		{
			/* Ricerca la posizione di sDocID nella collezione di FAOperation
			 * e restitusce l'elemento dove resource e from sono vuoti*/
			foreach (FormAttributeOperation o in this.IN)
			{
				if (String.Compare(sDocID,o.DocID)==0)
				{
					if ( (o.From==string.Empty) && (o.Resource==sRes) )
						return this.IN.IndexOf(o);
				}
			}
			return -1;
		}
		public int SearchDocIDForOUT(string sDocID, string sRes)
		{
			/* Ricerca la posizione di sDocID nella collezione di FAOperation
			 * e restitusce l'elemento dove resource e To sono vuoti*/
			foreach (FormAttributeOperation o in this.OUT)
			{
				if (String.Compare(sDocID,o.DocID)==0)
				{
					if ((o.To==string.Empty)&& (o.Resource==sRes))
						return this.OUT.IndexOf(o);
				}
			}
			return -1;
		}

		public void SortByDocID()
		{
			this.IN.SortByDocID();
			this.OUT.SortByDocID();
		}
		public void SortByResource()
		{
			this.IN.SortByResource();
			this.OUT.SortByResource();
		}
	}
}
